﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SalesTaxes
{
    public class Commodity : ITaxable
    {
        private string _name = string.Empty;

        public string Name
        {
            get { return _name; }
        }

        private decimal _preTaxPrice = 0.00M;

        public decimal PreTaxPrice
        {
            get { return _preTaxPrice*_count; }
        }

        private string _unit = string.Empty;

        public string Unit
        {
            get { return _unit; }
        }

        private int _count = 1;
        public int Count
        {
            get { return _count; }
        }

        private CommodityCategoory _caetgory = null;

        public CommodityCategoory Caetgory
        {
            get { return _caetgory; }
        }

        public double TaxRate
        {
            get { return _caetgory.Tax.TaxRate; }
        }


        private Commodity() { }
        public Commodity(string name, decimal PreTaxPrice, string unit,int cnt,
            CommodityCategoory category)
        {
            _name = name;
            _preTaxPrice = PreTaxPrice;
            _unit = unit;
            _count = cnt;
            _caetgory = category;
        }

        public decimal Cost()
        {
            decimal beforeRound=decimal.Round(this.PreTaxPrice * (decimal)TaxRate + PreTaxPrice, 2, MidpointRounding.AwayFromZero);
            int unit=(int)(beforeRound*100)%10;
            return ((unit < 5 && unit > 0) ? (beforeRound - (beforeRound * 100) % 10 / 100 + 0.05M) : beforeRound);
        }
    }


}
                        